package com.guoguo.service.impl;

import com.github.pagehelper.PageHelper;
import com.guoguo.base.PageBean;
import com.guoguo.entity.Menus;
import com.guoguo.mapper.MenusMapper;
import com.guoguo.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by KLSD on 2017/9/13.
 */
@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenusMapper menusMapper;


    @Override
    public PageBean<Menus> selectMenuList(int pageNumber, int pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        return new PageBean<Menus>(menusMapper.selectMenuList());
    }

    @Override
    public Menus selectByPrimaryKey(String menuId) {
        return menusMapper.selectByPrimaryKey(menuId);
    }

    @Override
    public int deleteByPrimaryKey(String menuId) {
        return menusMapper.deleteByPrimaryKey(menuId);
    }

    @Override
    public Menus addMenu(String menuId, String menuName, String menuDescription, String menuUrl, String menuParent,int menuType) {
       Menus menus=menusMapper.selectByPrimaryKey(menuId);
        if(menus==null){
            menus=new Menus(menuId,menuName,menuDescription,menuUrl,menuParent,menuType);
            int num=menusMapper.insertSelective(menus);
            return menus;

        }
        menus.setMenuId(menuId);
        menus.setMenuName(menuName);
        menus.setMenuDescription(menuDescription);
        menus.setMenuUrl(menuUrl);
        menus.setMenuParent(menuParent);
        menus.setMenuType(menuType);
        int num=menusMapper.updateByPrimaryKeySelective(menus);
        return menus;
    }

    @Override
    public List<Menus> selectMenus() {
        return menusMapper.selectMenus();
    }
}
